<?php
// +----------------------------------------------------------------------
// | my
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: $this <498944516@qq.com>
// +----------------------------------------------------------------------
namespace app\rob\model;

use think\Model;

class RobAppDo extends Model
{

    protected $table = "my_rob_app_do";
    protected $insert = ['status'=>1];  
    protected $autoWriteTimestamp = true;

    /**
     * 返回app处理规则
     */
    public function reply($data){
    	
      //处理找到合适的回复
      //只有关键字
      //有前面无后面
      //有前面后面需要分割
    
      $map['status']=['EGT',0];
      $map['app']=$data['app']['id'];
      if(!$data['before']){
       $map['before']=0; 
       }elseif(is_numeric($data['before']) || $data['before']=='{before}') {
       $map['before']=1; 
      } else {
       $map['before']=$data['before'];
      }

       if(!$data['back']  || $data['back']=='{back}'){
       $map['back']=0; 
       }else {
       $map['back']=1; 
       }
      

      $do=$this->where($map)->find();
     
      //统一处理
      
      if (!$do){
         if(!$data['before'] and !$data['back']) {
          $reply =$data['app']['description'];  //返回命令说明书
         }else{
          $reply='没有找到相关命令！';
         }
        
       }else{
      if ($do['model'] and $do['action']) $reply=model($do['model'])->$do['action']($data);
      }
      return $reply;
    		   
    }

   



    public function editData(){

      $data=input("post.");
      $data['aid']=session('aid');
      if (isset($data['id'])){
         $res = $this->allowField(true)->where('id',$data['id'])->update($data);
      }else{
         $data['aid']=session('aid');
         $res = $this->allowField(true)->data($data)->save();
      }
      
      return $res;
    }



    
}